﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace gChartSharp
{
    public class AxisLabelParam : IRenderable
    {

        /// <summary>
        /// The name of the API
        /// </summary>
        public string Name { get { return "chxl"; } }


        /// <summary>
        /// A list of data series - label pairs
        /// </summary>
        /// <remarks>
        /// i.e. Dictionary<0, new string[] { "Label1", "Label2" }>
        /// produces 0:|Label1|Label2 
        /// </remarks>
        public Dictionary<int, IEnumerable<string>> Labels 
        {
            get { return mLabels ?? (mLabels = new Dictionary<int, IEnumerable<string>>()); }
            set { mLabels = value; }
        }
        private Dictionary<int, IEnumerable<string>> mLabels;


        /// <summary>
        /// Render the text of the API
        /// </summary>
        /// <returns></returns>
        public string Render()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("&{0}=", this.Name);

            foreach (KeyValuePair<int, IEnumerable<string>> kv in this.Labels)
            {
                // only render the KeyValuePair if there is at least one label for the specified series
                if (kv.Value.Count() > 0 )
                {
                    sb.AppendFormat("{0}:|", kv.Key);

                    foreach (string label in kv.Value)
                        sb.AppendFormat("{0}|", label);
                }
            }

            // remove last '|'
            sb.Remove(sb.ToString().LastIndexOf('|'), 1);

            return sb.ToString();
        }

    }


    public enum AxisType
    {
        [DescriptionAttribute("x")]
        X,

        [DescriptionAttribute("y")]
        Y,

        [DescriptionAttribute("r")]
        Right,

        [DescriptionAttribute("t")]
        Top
    }
}
